package com.Prot2.Logger;

import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.provider.Settings;
import android.util.Log;

	public class WiFiWorker {

			private static final String TAG="GPSWorker";
			private ContentResolver wifiStringManager;
			private LocationContentObserver wifiStringObserver;
			private String wifiStatus;
			private Context mContext;
			
			
			public WiFiWorker(Context c){

				mContext=c;
				
				getWifiStatus();
				
				wifiStringManager = c.getContentResolver();
				wifiStringObserver= new LocationContentObserver ( new Handler(),c);
				//WifiManager.registerContentObserver(Settings.Secure.getUriFor(android.provider.Settings.Global.WIFI_ON), false, WifiObserver );
				wifiStringManager.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.WIFI_ON), false, wifiStringObserver );
				Log.w(TAG,"Wifi Observer started");
			}
			
			class LocationContentObserver extends ContentObserver {
				  public LocationContentObserver( Handler h, Context c ) {
				    super( h );
				  }

				  public void onChange(boolean selfChange) {
					  Log.w(TAG,"Wifi status changed!");
					  getWifiStatus();
				  }
				}
			
			private void getWifiStatus(){
				  //String mWifiStatus = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(), android.provider.Settings.Global.WIFI_ON);
				  String mWifiStatus = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(), Settings.Secure.WIFI_ON);

				  wifiStatus=mWifiStatus;
				  Log.w(TAG,"WifiStatus:"+mWifiStatus);
				  
				  
			}
			
			
			public String getRead(String DELIMITER){
				return wifiStatus;
			}
			
				
			public void stop(){
				wifiStringManager.unregisterContentObserver(wifiStringObserver);
				Log.w(TAG,"Wifi Observer stopped");
			}

		
		}


